$OpenBSD: patch-runjob_c,v 1.4 2013/06/04 13:47:10 giovanni Exp $
--- runjob.c.orig	2000-06-21 00:12:18.000000000 +0100
+++ runjob.c	2004-05-12 20:50:11.000000000 +0100
@@ -34,11 +34,38 @@
 #include <stdio.h>
 #include <string.h>
 #include "global.h"
+#include <limits.h>
 
 static int
 temp_file()
 /* Open a temporary file and return its file descriptor */
 {
+    char template[PATH_MAX];
+    char *tmpdir = getenv("TMPDIR");
+
+    int fd = -1;
+
+    if (tmpdir == NULL) {
+       tmpdir = "/tmp";
+    }
+    if (strlcpy(template, tmpdir, sizeof template) >=
+	sizeof template) {
+	die_e("TMPDIR too long.");
+    }
+    if (strlcat(template, "/anacronXXXXXXXXXX", sizeof template) >=
+	sizeof template) {
+	die_e("Temporary filename too long.");
+    }
+    if ((fd = mkstemp(template)) == -1) { 
+	die_e("Could not create temporary file.");
+    }
+    if (unlink(template) == -1) {
+	complain("Tried to unlink temporary file '%s' but failed.",
+	    template);
+    }
+    return fd;
+
+#if 0
     const int max_retries = 50;
     char *name;
     int fd, i;
@@ -61,6 +88,7 @@ temp_file()
     free(name);
     fcntl(fd, F_SETFD, 1);    /* set close-on-exec flag */
     return fd;
+#endif
 }
 
 static off_t
